package stark.app.function.filetransfer;

import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.AppUtils;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import stark.app.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;

/**
 * Author：daizhongbin on 2023/6/28
 * Email：1027154338@qq.com
 * Desc:
 */
public class ApkAdapter extends StkProviderMultiAdapter<ApkBean> {

    public ApkAdapter() {
        super(1);
        addItemProvider(new ItemProvider());
    }

    private class ItemProvider extends BaseItemProvider<ApkBean> {

        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_apk;
        }

        @Override
        public void convert(@NonNull BaseViewHolder holder, ApkBean apkBean) {
            String pkgName = apkBean.pkgName;
            holder.setImageDrawable(R.id.ivIcon, AppUtils.getAppIcon(pkgName));
            holder.setText(R.id.tvName, AppUtils.getAppName(pkgName));
            String versionName = "(" + AppUtils.getAppVersionName(pkgName) + ")";
            holder.setText(R.id.tvVersion, versionName);
            holder.setText(R.id.tvPackage, pkgName);
            ImageView ivSel = holder.getView(R.id.ivSel);
            ivSel.setSelected(apkBean.isSelected());
        }
    }

}
